package web;

import cz.muni.fi.pv168.ContactManager.DBUtil;
import cz.muni.fi.pv168.ContactManager.PersonManagerImpl;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.sql.DataSource;

//import org.apache.commons.dbcp.BasicDataSource;

//import org.apache.commons.dbcp.BasicDataSource;

@WebListener
public class StartListener implements ServletContextListener {

    @Resource(name="jdbc/contact")
    private DataSource source;

    @Override
    public void contextInitialized(ServletContextEvent ev) {
        ServletContext servletContext = ev.getServletContext();

        PersonManagerImpl manager = new PersonManagerImpl();
        //manager.setDataSource(DBUtil.getDataSource());
        DBUtil.restartDB(source);
        manager.setDataSource(source);
        servletContext.setAttribute("manager",manager);
    }

    @Override
    public void contextDestroyed(ServletContextEvent ev) {

    }
}